package com.结构型模型.J组合模式;

import java.util.ArrayList;
import java.util.List;

/**
 *Menu类已经实现了除了getName方法的其他所有方法，因为Menu类具有添加菜单，移除菜单和获取子 菜单的功能
 */
public class Menu extends MenuComponent{
    List<MenuComponent> menuComponentList;

    public Menu(String name,int level) {
      this.name=name;
      this.level=level;
      menuComponentList=new ArrayList<MenuComponent>();
    }


    void  add(MenuComponent menuComponent){
        menuComponentList.add(menuComponent);
    }

    void  remove(MenuComponent menuComponent){
        menuComponentList.remove(menuComponent);
    }

    MenuComponent getChild(int i){
        return menuComponentList.get(i);
    }



    void print(){
        for (int i = 0; i <level ; i++) {
            System.out.print("--");
        }
        System.out.println(name);
        for (MenuComponent menuComponent:menuComponentList
             ) {
            menuComponent.print();
            
        }
        
    }


}
